using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSRI.HelperClasses;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace SMS.VE.Library.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class SmsManagerFixture
    {
        static Database db;
        /// <summary>
        /// This database instance should not be changed by the tests.
        /// </summary>
        static Database readOnlyDb;

        public SmsManagerFixture()
        {}

        [ClassInitialize()]
        public static void ClassInitialize(TestContext testContext) 
        {
            db = DatabaseFactory.CreateDatabase("SMS.VE.MessagesDatabase");
            readOnlyDb = DatabaseFactory.CreateDatabase("SMS.VE.MessagesDatabase.ReadOnly");
        }

        [TestMethod]
        public void SaveAndGetSavedMessage()
        {
            SmsManager manager = new SmsManager(db);

            SmsClass sms = new SmsClass();
            sms.Time = DateTime.Now;
            sms.MessageID = Guid.NewGuid();
            sms.Number = "1144556677";
            SmsExtension smsExtension = new SmsExtension(sms, new LatLong(12.12, 34.34), "testing message", "testing sender");

            manager.Save(smsExtension);

            Assert.IsNotNull(manager.GetMessage(delegate(SmsExtension s) { return s.Sms.MessageID.Equals(sms.MessageID); }));
        }

        [TestMethod]
        public void GetAllMessagesReturnsAll()
        {
            SmsManager manager = new SmsManager(readOnlyDb);

            Assert.AreEqual(2, new List<SmsExtension>(manager.GetAllMessages()).Count);
        }
    }
}